package com.example.huitong.bean;

import java.io.Serializable;
import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * 物流信息
 * @author ville
 */
/*
 * 
 *  {
    "status":"3",
    "message":"",
    "errCode":"0",
    "data":[
    	{"time":"2014-03-10 19:22","context":"西安太元路(西安太元路) 已收件"},
    	{"time":"2014-03-10 19:22","context":"离开 西安太元路 发往西安北郊中转站"},
    	{"time":"2014-03-10 19:36","context":"到达 西安北郊中转站 上一站 西安太元路"},
    	{"time":"2014-03-10 22:16","context":"到达 西安 上一站 西安北郊中转站"},
    	{"time":"2014-03-10 22:37","context":"离开 西安 发往深圳中心"},
    	{"time":"2014-03-10 23:52","context":"在 西安 装包并发往广州中心"},
    	{"time":"2014-03-12 10:29","context":"所在包 到达广州中心"},
    	{"time":"2014-03-12 10:30","context":"在 广州中心 装包并发往深圳中心"},
    	{"time":"2014-03-12 15:14","context":"所在包 到达深圳中心"},
    	{"time":"2014-03-12 15:20","context":"到达 深圳中心 上一站 广州中心"},
    	{"time":"2014-03-12 15:26","context":"离开 深圳中心 发往深圳南山"},
    	{"time":"2014-03-13 08:17","context":"到达 深圳南山 上一站 深圳中心"},
    	{"time":"2014-03-13 11:44","context":"深圳南山 张东林 正在派件中"},
    	{"time":"2014-03-13 13:55","context":"已签收,签收人是 拍照签收 查看签收图片"}
    	],
    "html":"",
    "mailNo":"761303055403",
    "expTextName":"中通快递",
    "expSpellName":"zhongtong",
    "update":"1395904261",
    "cache":"300",
    "ord":"ASC",
    "tel":"021-39777777"
    }
 * */

/*
 *{
 *	"nu":"768685345166",
 *	"message":"ok",
 *"ischeck":"1",
 *"companytype":"shentong",
 *"com":"shentong",
 *"updatetime":"2014-05-13 17:50:51",
 *"condition":"F00",
 *"status":"200",
 *"codenumber":"768685345166",
 *"state":"3",
 *"data":[
 *{"time":"2014-04-07 13:05:47","context":"已签收,签收人是已签收","ftime":"2014-04-07 13:05:47"},
 *{"time":"2014-04-07 08:13:48","context":"上海宝山公司 的派件员 樊均武 正在派件","ftime":"2014-04-07 08:13:48"},
 *{"time":"2014-04-07 05:35:24","context":"快件已到达上海宝山公司","ftime":"2014-04-07 05:35:24"},
 *{"time":"2014-04-07 05:34:10","context":"由上海中转部 发往 上海宝山公司","ftime":"2014-04-07 05:34:10"},
 *{"time":"2014-04-07 01:38:59","context":"由浙江杭州中转部 发往 上海中转部","ftime":"2014-04-07 01:38:59"},
 *{"time":"2014-04-06 20:28:25","context":"由浙江永康公司 发往 浙江义乌中转部","ftime":"2014-04-06 20:28:25"},
 *{"time":"2014-04-06 20:28:25","context":"浙江永康公司 正在进行 装袋 扫描","ftime":"2014-04-06 20:28:25"},
 *{"time":"2014-04-06 20:25:13","context":"浙江永康公司 的收件员 浙江永康1已收件","ftime":"2014-04-06 20:25:13"}
 *]} 
 */
/**
 * @author ville
 *
 */
/**
 * @author ville
 *
 */
public class LogisticInfo implements Serializable {
	private static final long serialVersionUID = -6942824467621714082L;
	String nu;
	public String message; 
	String com;
	String updatetime;
	public int status;
	private int state = -1;
	public ArrayList<Data> dataList = new ArrayList<Data>();
	
	public static class Data{
		public String time;
		public String context;
		Data(JSONObject jObj){
			time = jObj.optString("time");
			context = jObj.optString("context");
		}
	}
	public static LogisticInfo constructInfo(String jsonStr) {
		// TODO Auto-generated constructor stub
		LogisticInfo info = new LogisticInfo();
		try {
			JSONObject obj = new JSONObject(jsonStr);
			info.nu = obj.optString("nu");
			info.message = obj.optString("message");
			info.com = obj.optString("com");
			info.status = obj.optInt("status");
			info.state = obj.optInt("state");
			info.updatetime = obj.optString("updatetime");
			JSONArray dataArray = obj.optJSONArray("data");
			if(dataArray != null){
				int len = dataArray.length();
				for(int i = 0; i < len; i++){
					JSONObject dataItem = dataArray.getJSONObject(i);
					info.dataList.add(new Data(dataItem));
				}
			}
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			info = null;
			e.printStackTrace();
		}
		return info;
	}
	@Override
	public String toString() {
		return "LogisticInfo [nu=" + nu + ", message=" + message + ", com="
				+ com + ", updatetime=" + updatetime + ", status=" + status
				+ ", state=" + state + ", dataList=" + dataList + "]";
	}
	
	public String parseState(){
		String s = "未知";
		switch (state) {
		case 0:
			s = "在途";
			break;
		case 1:
			s = "揽件";
			break;
		case 2:
			s = "疑难";
			break;
		case 3:
			s = "签收";
			break;
		case 4:
			s = "退签";
			break;
		case 5:
			s = "派件";
			break;
		case 6:
			s = "退回";
			break;
		}
		return s;
	}
}
